/**
 * 修改密码
 * @author Qasim <15750783791@163.com>
 * @version 2016/9/6
 */
var self = '';
document.addEventListener('plusready' , ready ,  false);

function ready(){  
	
	self = plus.webview.currentWebview(); 
	
	var memberInfo = plus.storage.getItem('memberInfo'); 
	
	memberInfo = $.parseJSON(memberInfo);
	
	//修改密码 
	$('.update_pass').on('click' , function(){
		
		var pass = $('input[name=pass]').val() , new_pass = $('input[name=new_pass]').val() , new_repass = $('input[name=new_repass]').val();
		
		if(!pass.trim() || !new_pass.trim() ||!new_repass.trim()){
			
			toast('输入框不能为空'); return;
			
		}
		
		if(new_pass != new_repass){
			
			toast('两次密码不一致'); return;
				
		}
		
		if(pass == new_pass){ 
			
			toast('新密码与原密码相同'); return;
			
		}
		
		plus.nativeUI.showWaiting('修改中...');
		
//		console.log(memberInfo.aid + ',' + pass + ',' +new_pass)
		
		$.ajax({
			
			url : apiRoot + '/Home/Member/updatePassword/' , 
			
			type : 'post' , 
			
			data : {
				
				aid : memberInfo.aid,
				
				pass : pass , 
				
				new_pass : new_pass 
				
			} , 
			
			success : function(data){
				
				plus.nativeUI.closeWaiting();
				
				if(data == -1){
					
					toast('原密码错误');
					
					
				}else{
					
					toast('修改成功');
					
					plus.storage.removeItem('memberInfo');
					
 					openNewpage('login.html')
 					
				}
				
			} , 
			error : function(e){
				
				plus.nativeUI.closeWaiting();
				
				toast('连接超时 ，请检查网络');
				
			}
		})
	})
}
